/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Model;

import DAOInterface.AbstractDAOMapFactory;
import DAOInterface.DAOConnection;
import ModelInterface.IModelMainMapping;
import java.sql.DatabaseMetaData;
import java.sql.ResultSet;
import java.util.ArrayList;

/**
 *
 * @author Fabian
 */
public class ModelMainMapping implements IModelMainMapping {

    /**
     * 
     */
    public DatabaseMetaData metadatosS;
    /**
     * 
     */
    public DatabaseMetaData metadatosT;
    private DAOConnection conectorDBSource;
    private DAOConnection conectorDBTarget;

    /**
     * 
     * @param path
     * @param dbName
     * @param user
     * @param pass
     * @param type
     * @return
     */
    @Override
    public boolean setDBConnectionSource(String path, String dbName, String user, String pass, int type) {
        //throw new UnsupportedOperationException("Not supported yet.");
        conectorDBSource = AbstractDAOMapFactory.getAbstractControllerFactory(type).getDBConnector();
        if (conectorDBSource.setConnection(path, dbName, user, pass)) {
            metadatosS = conectorDBSource.getModel();
            return true;
        }
        return false;
    }

    /**
     * 
     * @return
     */
    @Override
    public DatabaseMetaData getModelDBs() {
        return metadatosS;
    }

    /**
     * 
     * @param tabla
     * @param columna
     * @return
     */
    @Override
    public ResultSet getColumnSource(String tabla, String columna) {
        return conectorDBSource.getColumn(tabla, columna);
    }

    /**
     * 
     * @param path
     * @param dbName
     * @param user
     * @param pass
     * @param type
     * @return
     */
    @Override
    public boolean setDBConnectionTarget(String path, String dbName, String user, String pass, int type) {
        //throw new UnsupportedOperationException("Not supported yet.");
        conectorDBTarget = AbstractDAOMapFactory.getAbstractControllerFactory(type).getDBConnector();
        if (conectorDBTarget.setConnection(path, dbName, user, pass)) {
            metadatosT = conectorDBTarget.getModel();
            return true;
        }
        return false;
    }

    /**
     * 
     * @return
     */
    @Override
    public DatabaseMetaData getModelDBt() {
        return metadatosT;
    }

    /**
     * 
     * @return
     */
    @Override
    public DAOConnection getDBConnectionTarget() {
        return this.conectorDBTarget;
    }

    /**
     * 
     * @return
     */
    @Override
    public DAOConnection getDBConnectionSource() {
        return this.conectorDBSource;
    }

    /**
     * 
     * @param tabla
     * @param columnas
     * @param filtro
     * @return
     */
    @Override
    public ResultSet getElement(String tabla, ArrayList columnas, String filtro) {
        return this.conectorDBSource.getElement(tabla, columnas, filtro);
    }
}
